package com.zjh.photoshopstudy.app.register;

import com.zjh.photoshopstudy.Model.AppUserEntity;
import com.zjh.photoshopstudy.Utils.SharePreferencesUtils;

public class RegisterPresent {
    private RegisterActivity mActivity;
    private RegisterHttp mHttp;

    public RegisterPresent(RegisterActivity loginActivity) {
        mActivity = loginActivity;
        mHttp = new RegisterHttp();
    }

    protected void register(String username, String password, String confirmPassword) {
        mHttp.register(new RegisterCallBack(), username, password);
    }

    public void checkUserNmae(String username) {
        mHttp.checkUser(new CheckUserNameCallBack(), username);
    }

    class CheckUserNameCallBack {
        public void checkSuccess() {
            mActivity.onCheckSuccess();
        }

        public void checkFail() {
            mActivity.onCheckFail();
        }
    }

    protected class RegisterCallBack {
        public void onRegisterSuccess(AppUserEntity user) {
            SharePreferencesUtils.saveLoginUser(user, mActivity);
            mActivity.onRegisterSuccess();
        }

        public void onRegisterFail() {
            mActivity.onRegisterFail();
        }
    }
}
